/*
 * @Author: your name
 * @Date: 2021-05-31 15:50:51
 * @LastEditTime: 2021-05-31 16:04:11
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \egg-demo\database\migrations\20210531075051-init-goods.js
 */
'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    /**
     * Add altering commands here.
     *
     * Example:
     * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */
    const { INTEGER, BIGINT, ENUM, DATE, STRING, UUIDV4, UUID } = Sequelize;
    await queryInterface.createTable('goods_groups', {
      uuid: {
        type: STRING(38),
        allowNull: false,
        primaryKey: true,
        defaultValue: UUIDV4,
      },
      created_at: DATE,
      updated_at: DATE,
      created_use_uuid: {
        type: UUID,
        allowNull: true,
        references: {
          model: 'users',
          key: 'uuid',
        },
        onUpdate: 'cascade',
        onDelete: 'cascade',
      },
      name: {
        type: STRING(128),
        allowNull: false,
        comment: "商品品类名",
      },
      intro: {
        type: STRING(255),
        allowNull: true,
        comment: "商品品类介绍",
      },
      deleted: {
        type: ENUM('0', '1'),
        allowNull: false,
      }
    })
  },

  down: async (queryInterface, Sequelize) => {
    /**
     * Add reverting commands here.
     *
     * Example:
     * await queryInterface.dropTable('users');
     */
    await queryInterface.dropTable("goods_groups");
  }
};
